﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class ShipSwitchPanel : MonoBehaviour
{
    public GameObject m_ShipSwitcher;
    public GameObject m_ShipSwitcheItem;

    public GameObject m_ShipSwitcherExpandB;
    public GameObject m_ShipSwitcherReduceB;

    public AudioSource m_DingSound;
    public ShipDescriptionPanel m_ShipDescriptionPanel;
    void Start()
    {
        /// 初始化选择舰船界面的Item
        for (int i = 0; i < Player.Instance.m_Ships.Count; ++i)
        {
            Ship ship = Player.Instance.m_Ships[i];
            GameObject item = Instantiate(m_ShipSwitcheItem);
            item.transform.SetParent(m_ShipSwitcher.transform);
            item.transform.localScale = new Vector3(1,1,1);
            ShipSwitchItem itemCom = item.GetComponent<ShipSwitchItem>();
            itemCom.Ship = ship;
            itemCom.Index = i;
            itemCom.m_Panel = this;
            itemCom.m_ShipDescriptionPanel = m_ShipDescriptionPanel;
        }
        Player.Instance.SelectShip = Player.Instance.SelectShip;
    }

    // Update is called once per frame
    void Update()
    {
#if UNITY_ANDROID
        if (!UtilsUnity.IsOnUI(Input.mousePosition) && (Input.touchCount > 1 || Input.GetMouseButtonDown(0)))
        {
            m_ShipDescriptionPanel.gameObject.SetActive(false);
        }
#else
        if (!EventSystem.current.IsPointerOverGameObject())
        {
            m_ShipDescriptionPanel.gameObject.SetActive(false);
        }
#endif
    }

    public void Ding()
    {
        m_DingSound.Play();
    }
}
